package com.token.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.token.mapper.DicDataMapper;
import com.token.model.po.DicData;
import com.token.service.DictDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @auther: henriy
 * @Date: 2023/10/26
 */
@Service
public class DictDataServiceImpl implements DictDataService {

    @Resource
    private DicDataMapper dicDataMapper;

    @Override
    public String getDictValueByCode(String dictCode, String code) {
        LambdaQueryWrapper<DicData> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(DicData::getValue, code).eq(DicData::getDicTypeCode, dictCode);
        DicData dicData = dicDataMapper.selectOne(queryWrapper);
        if (Objects.nonNull(dicData)) {
            return dicData.getLabel();
        }

        return null;
    }
}
